<?php
$ID="";
$local="user01";
$remote="user02";
if(isset($_GET['local'])) {
    $local=$_GET['local'];
	$user_file = "users/".md5($local)."/settings.json";
	$profile= json_decode(file_get_contents($user_file),true);
	$ID=$profile['identity'];
}
if(isset($_GET['remote']))
    $remote=$_GET['remote'];
?>
<form name="data" action="left.php" method="get">
<?php
echo "Your ID:<input type=\"text\" name=local value=\"$local\"></input><BR>";
echo "Remote ID:<input type=\"text\" name=remote value=\"$remote\"></input><BR>";
echo "Your Identify:<input type=\"text\" name=id value=\"$ID\"></input><BR>";
echo "<input type=submit value=submit>";
?>
</form>
<?php
echo "<a href=\"javascript:void(0)\" onclick=\"window.open('settings.php?uid=$local');\">Settings</a>";
?>

<?php
if(!isset($_GET['local']))
        $local='user01';
else
        $local=$_GET['local'];

if(!isset($_GET['remote']))
        $remote='user02';
else
        $remote=$_GET['remote'];

        echo "<H5>Local is $local and Remote is $remote</H1>";
if(strstr($ID,"student") != null) {
        $pw=0;$ph=0;
        $mw=160;$mh=120;
}
else if(strstr($ID,"teacher")!=null){
        $pw=160;$ph=120;
        $mw=0;$mh=0;
}
else {
        $pw=160;$ph=120;
        $mw=160;$mh=120;
}

?>


<?php
echo "<object type=\"application/x-shockwave-flash\" data=\"VideoIO.swf\"
    id=\"videoLocal\" width=\"$pw\" height=\"$ph\">";
#<object type="application/x-shockwave-flash" data="VideoIO.swf"
#    id="videoLocal" width="160" height="120">"
?>
    <param name="movie" value="VideoIO.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#000000" />
    <param name="allowFullScreen" value="false" />
    <param name="allowScriptAccess" value="" />
    <param name="flashVars"
    value="controls=true&url=rtmp://192.168.2.104/myapp&<?php echo "publish=$local";?>&record=false" />
</object>

<?php
echo "<object type=\"application/x-shockwave-flash\" data=\"VideoIO.swf\"
    id=\"videoRemote\" width=\"$mw\" height=\"$mh\">";
#<object type="application/x-shockwave-flash" data="VideoIO.swf"
#    id="videoRemote" width="160" height="120">"
?>
    <param name="movie" value="VideoIO.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#000000" />
    <param name="allowFullScreen" value="true" />
    <param name="allowScriptAccess" value="" />
    <param name="flashVars"
    value="controls=true&url=rtmp://192.168.2.104/myapp&<?php echo "play=$remote"; ?>&record=false" />
</object>
<script lang=javascript>
	setTimeout("online_update()", 1000);
	setTimeout("online_rand()",1000);
    function online_update(){
        var ajaxRequest;  // The variable that makes Ajax possible!
		setTimeout("online_update()", 10000);

        ajaxRequest = new XMLHttpRequest();
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                        //The response
					if(ajaxRequest.responseText != "online")
						document.getElementById('online_update').innerHTML = "offline";
					else
						document.getElementById('online_update').innerHTML = ajaxRequest.responseText;
					//var textarea = document.getElementById('online_update');;
					//textarea.scrollTop = textarea.scrollHeight;;
                }
        }
<?php
      echo "ajaxRequest.open(\"GET\", \"online_ping.php?uid=$local\", true);";
?>
        ajaxRequest.send(null);
}
    function online_rand(){
        var ajaxRequest;  // The variable that makes Ajax possible!
		setTimeout("online_rand()",1000*30);

        ajaxRequest = new XMLHttpRequest();
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                        //The response
					document.getElementById('rand_online').innerHTML = ajaxRequest.responseText;
					//var textarea = document.getElementById('online_update');;
					//textarea.scrollTop = textarea.scrollHeight;;
                }
        }
<?php
      echo "ajaxRequest.open(\"GET\", \"show_rand_online.php?uid=$local\", true);";
?>
        ajaxRequest.send(null);
}
</script>
<div id='online_update'>
</div>
<BR>
<div id='rand_online'>
</div>
